package com.reggie.background.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.reggie.background.common.ThreadLocalUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("自动填充插入的employee的属性");
        log.info("本次请求线程id为{}",Thread.currentThread().getId());
        metaObject.setValue("createTime", new Date());
        metaObject.setValue("updateTime", new Date());
        metaObject.setValue("createUser", ThreadLocalUtils.getThreadLocalValue());
        metaObject.setValue("updateUser",ThreadLocalUtils.getThreadLocalValue());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("自动填充更新的employee的属性");
        log.info("本次请求线程id为{}",Thread.currentThread().getId());
        metaObject.setValue("updateTime", new Date());
        metaObject.setValue("updateUser",ThreadLocalUtils.getThreadLocalValue());
    }

}
